var app = getApp();
var baseUrl = app.globalData.baseUrl;
const apiRequest = (url, method, data, id) => {
    let header = {
        userType: '2',
        type: '2',
        // wx.getStorageSync('requestParameter_shopId') ||
        requestParameter_shopId: 100,
        //门店id
        'Content-Type': 'application/json;charset=utf-8',
        'App-Channel': 'miniApp',
        Accept: 'application/json, text/plain, */*',
        Authorization: 'Bearer' + uni.getStorageSync('token')
    };
    let promise = new Promise(function (resolve, reject) {
        uni.request({
            url: baseUrl + url,
            data: data ? data : {},
            method: method,
            header: header,
            params: {},
            success: function (res) {
                if (res.data.code == 0) {
                    resolve(res.data);
                } else if (res.data.msg === 'token expire') {
                    uni.showToast({
                        title: '请登录',
                        icon: 'none',
                        duration: 1000
                    });
                    setTimeout(() => {
                        uni.navigateTo({
                            url: '/pages/login/index'
                        });
                    }, 1000);
                } else {
                    reject(res.data);
                }
            },
            fail: function (res) {
                uni.showToast({
                    title: '2' + (res.errMsg || '未知错误'),
                    icon: 'error',
                    duration: 2000
                });
            }
        });
    });
    return promise;
};
export default apiRequest;
